const { readStatic } = require("./api/static");
const doCalc = require("./api/calc");

/* 
http://localhost:8000/files/pages/home.html
http://localhost:8000/files/pages/login.html
http://localhost:8000/files/js/cookies.js
*/

const requestHandler = (req, res) => {
    console.log("url", req.url);
    // res.setHeader("access-control-allow-origin","*")
    res.setHeader("Content-Type","application/json;charset=utf8")

    switch (true) {
        /* 静态文件处理 */
        case req.url.startsWith("/files"):
            readStatic(req,res)
            break;
        case req.url.startsWith("/calc"):
            doCalc(req,res)
            break;

        default:
            res.setHeader("Content-Type", "text/html;charset=utf-8");
            res.end("<h3>404您要找的页面不翼而飞o(╥﹏╥)o</h3>");
            break;
    }
};

module.exports = requestHandler;
